#include <bits/stdc++.h>

using namespace std;

const int N = 5010;

int n;
int f[N];

int main()
{
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin(), a.end());
    for (int i = 0; i < a.size(); ++i)
    {
        f[i] = 1;
        for (int j = 0; j < i; ++j)
        {
            if (a[j].second < a[i].second)
            {
                f[i] = max(f[i], f[j] + 1);
            }
        }
    }
    int ret = 0;
    for (int i = 0; i < n; ++i)
    {
        ret = max(ret, f[i]);
    }
    cout << ret << endl;
    return 0;
}
